<template>
	<view>
		<uni-grid :column="3" :square="false">
			<uni-grid-item v-for="(b,i) in brandsList" :key="i">
				<view class="brand" @click="showProduct(i)">
					<uni-badge :offset=[13,0] :text="b.popularity" type="error" absolute="rightTop" :maxNum=9999 >
						<image :src="$url.base+b.logo" mode="widthFix" />
					</uni-badge>
					<text>{{b.bname}}</text>
				</view>
			</uni-grid-item>
		</uni-grid>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				brandsList	:[]
			};
		},
		onLoad() {
			// 页面加载时，异步请求品牌信息
			uni.showLoading({
				title: '内容加载中...',
			})
			let url = this.$url.brandsList				
			// console.log(url)
			uni.request({
				url,
				success: res => {
					// console.log(res.data)
					this.brandsList	=res.data
				},
				fail: res => {
					console.log(err)
				},
				complete: () => {
					uni.hideLoading()
				}

			})
		},
		methods: {
			showProduct(i) {
				let bname=this.brandsList[i].bname  //品牌名称
				let kw = this.brandsList[i].keywords  //该品牌的商品搜索时的关键字
				uni.navigateTo({
					url:`../product-list/product-list?bname=${bname}&kw=${kw}`
				})
			}
		},
	}
</script>

<style lang="scss">
	.brand {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: $uni-spacing-col-lg 0;

		image {
			width: 220rpx;
		}

		text {
			margin: $uni-spacing-col-lg 0 0 0;
		}
	}
</style>
